package com.example.yuwei.mediaplayer.view;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.PowerManager;
import android.support.annotation.Nullable;
import android.util.Log;
import com.example.yuwei.mediaplayer.presenter.MusicPresenter;
/**
 * @author yuwei
 */
public class PlayService extends Service {
    private static String TAG = "PlayService";
    private MusicPresenter musicPresenter;
    private PowerManager.WakeLock mWakeLock;
    @Override
    public void onCreate() {
        Log.i(TAG, "onCreate: ");
        super.onCreate();
        musicPresenter = MusicPresenter.getInstance();
        //通知栏的创建
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "onBind: ");
        return null;
    }
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand: ");
        String type = intent.getStringExtra("type");
        Log.i(TAG, "onStartCommand: "+type);
        if(type != null){
            switch (type){
                case"playOrPause":musicPresenter.playOrPause();
                    break;
                case"previous":musicPresenter.previous();
                    break;
                case "next":musicPresenter.next();
                    break;
                case"setMode":musicPresenter.setMode();
                    break;
                case"progress":musicPresenter.progressPlay();
                    break;
                case"select":musicPresenter.play(intent.getIntExtra("position",0));
                    break;
                case "restart":Intent intent1 = new Intent(this,MainActivity.class);
                               startActivity(intent1);
                default:
            }
        }
        Log.i(TAG, "onStartCommand: ");
        return START_REDELIVER_INTENT;
    }

    @Override
    public void onDestroy() {
        Log.i(TAG, "onDestroy: Service");
        musicPresenter.stop();
        super.onDestroy();
    }
}
